//#include "threadpool.hpp"
#include <iostream>
#include <thread>
#include <condition_variable>
#include <mutex>

int cnt=0;
std::mutex mutex;
std::condition_variable con;

int main()
{
	std::thread t1([&](){
		while(true)
		{
			std::unique_lock<std::mutex> lock(mutex);
			con.wait(lock,[&](){
				return cnt%2==0||cnt>=10;
			});
			if(cnt>=10)
			{
				con.notify_one();
				break;
			}
			cnt++;
			std::cout<<"当前是t1:"<<cnt<<std::endl;
			con.notify_one();
		}
	});
	std::thread t2([&](){
		while(true)
		{
			std::unique_lock<std::mutex> lock(mutex);
			con.wait(lock,[&](){
				return cnt%2==1||cnt>=10;
			});
			if(cnt>=10)
			{
				con.notify_one();
				break;
			}
			cnt++;
			std::cout<<"当前是t2:"<<cnt<<std::endl;
			con.notify_one();
		}
	});
	t1.join();
	t2.join();
	return 0;
}